package cn.findviewbydream.controller;

import cn.findviewbydream.dto.Result;
import cn.findviewbydream.entity.PostEntity;
import cn.findviewbydream.service.PostService;
import cn.findviewbydream.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**********************************
 * 工程：cn.findviewbydream.controller
 * 作者：白雨濃 evil
 * 时间：17-6-2 上午11:26
 * 邮箱：evilbai@foxmail.com
 * 内容：贴子信息相关
 **********************************/
@RestController
@RequestMapping("/post")
public class PostController
{
    private final PostService service;

    @Autowired
    public PostController(PostService service)
    {
        this.service = service;
    }

    @GetMapping("/list")
    public Result getPostList()
    {
        return ResultUtil.success(service.getPostList());
    }

    @GetMapping("/{postId}")
    public Result getPost(@PathVariable int postId)
    {
        return ResultUtil.success(service.getPost(postId));
    }

    @PostMapping("")
    public Result postPost(@Valid PostEntity entity, HttpSession session, BindingResult result)
    {
        return ResultUtil.success(service.postPost(entity, session));
    }

}
